<!--
 * @Descripttion: 专家端预约页面
 * @version: 
 * @Author: lihk
 * @Date: 2023-12-28 16:55:56
 * @LastEditors: lihk
 * @LastEditTime: 2024-01-04 10:16:59
-->
<template>
  <view>
    <view>
      <Date @change="changeDate"></Date>
    </view>
    <view class="order" v-for="item in appointmentsList" @click="toChat(item)">
      <img :src="item.order_headUrl" alt="">
      {{item.order_name}}
    </view>
  </view>
</template>

<script>
import { getProfessorAppointments, getUserInfo } from '../../utils/http';
import Date from '../../components/date/date.vue'
export default {
  components: {
    Date
  },
  data () {
    return {
      professorParams: {},
      appointmentsList: [],
    };
  },
  created () {
    this.$route.query.professorId = Number(this.$route.query.professorId)
    this.$route.query.userId = Number(this.$route.query.userId)
    this.professorParams = this.$route.query
  },
  computed: {

  },
  methods: {
    changeDate (e) {
      this.professorParams = { ...this.professorParams, ...e }
      this.getAppointment()
    },
    async getAppointment () {
      const { data } = await getProfessorAppointments(this.professorParams)
      for (const element of data) {
        const userInfo = await this.getUserInfo(element.userId);
        if (userInfo) {
          element.order_headUrl = userInfo.headUrl;
          element.order_name = userInfo.lastName;
        }
      }
      this.appointmentsList = data
      console.log("🚀 ~ file: appointments.vue:21 ~ getAppointment ~ data:", this.appointmentsList, data)
    },
    async getUserInfo (userId) {
      const { data } = await getUserInfo(userId)
      return data
    },
    toChat (item) {
      uni.navigateTo({
        url: '/pages/chat/chat?professorId=' + this.professorParams.professorId + '&userId=' + item.userId
      })
    }

  }
}
</script>

<style lang="scss">
.order {
  display: flex;
  margin-bottom: 10px;
  img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-right: 20px;
  }
}
</style>
